﻿
Imports SponsorshipLogic
Imports SponsorshipLogic.Activity

Public Class ctlRecentActivity

    Public Event OpenActivity(ByVal ActivityType As ActivityType, ByVal ActivityId As Integer)
    Public Event Reload()

    Public WriteOnly Property ActivityTypes As DataTable
        Set(ByVal value As DataTable)
            With cboActivityType
                Dim dr As DataRow
                dr = value.NewRow()
                dr(0) = 0
                dr(1) = "All Activity Types"
                value.Rows.InsertAt(dr, 0)
                .DataSource = value
                .DisplayMember = "name"
                .ValueMember = "activityTypeId"
                .SelectedValue = 0
            End With
        End Set
    End Property

    Public Property ActivityTypeFilter As Activity.ActivityType
        Get
            ActivityTypeFilter = cboActivityType.SelectedValue
        End Get
        Set(ByVal value As Activity.ActivityType)
            cboActivityType.SelectedValue = value
        End Set
    End Property

    Public WriteOnly Property DataTable As DataTable

        Set(ByVal value As DataTable)

            With grdRecentActivity
                .DataSource = value
                .Columns("activityTypeId").Visible = False
                .Columns("activityId").Visible = False
                .BackgroundColor = Color.AliceBlue
            End With

        End Set
    End Property

    Private Sub btnOpenActivity_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenActivity.Click
        Dim ActivityType As ActivityType
        Dim Activity As Integer

        If grdRecentActivity.SelectedRows.Count > 0 Then
            For Each row As DataGridViewRow In grdRecentActivity.SelectedRows
                With row
                    ActivityType = .Cells("activityTypeId").Value
                    Activity = .Cells("activityId").Value
                    RaiseEvent OpenActivity(ActivityType, Activity)
                End With
            Next
        End If
    End Sub

    Private Sub btnReload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReload.Click
        RaiseEvent Reload()
    End Sub

    Private Sub cboActivityType_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs)
        RaiseEvent Reload()
    End Sub

    Private Sub cboActivityType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboActivityType.SelectedIndexChanged

    End Sub
End Class
